<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Portfolio_Model extends CI_Model
    {
	function lists($p=1,$limit=50,$status=FALSE)
	{
	    $start = ($p-1)*$limit;
	    
	    $where = '';
	    if($status){
		$where = "WHERE `p_active`={$status}";
	    }
	    
	    $sql = "SELECT * FROM portfolio {$where} LIMIT {$start},{$limit}";
	    $query = $this->db->query($sql);
	    return $this->db->result_array($query);
	}
	
	function get_all($status=FALSE)
	{
	    $where = '';
	    if($status){
		$where = "WHERE `p_active`={$status}";
	    }
	    
	    $sql = "SELECT * FROM portfolio {$where}";
	    $query = $this->db->query($sql);
	    return $this->db->result_array($query);
	}
	
	function count_all($status=FALSE)
	{
	    if($status){
		$where = "`p_active`={$status}";
		return $this->db->countOf('portfolio', $where);
	    }else{
		return $this->db->countOfAll('portfolio');
	    }
	}
	
	function get_info($id=FALSE)
	{
	    if($id){
		$sql = "SELECT * FROM portfolio WHERE p_id=$id";
		return $this->db->queryUniqueRow($sql);
	    }
	    
	    return FALSE;
	}
	
	function gallery_lists($p_id , $status=FALSE)
	{
	    $where = '';
	    if($status){
		$where = "AND `pi_active`={$status}";
	    }
	    
	    $sql = "SELECT * FROM portfolio_img WHERE p_id={$p_id} {$where}";
	    $query = $this->db->query($sql);
	    return $this->db->result_array($query);
	}
    }